/**
 * <p>Title: PostAction.java</p>
 * <p>Description: DoNotes</p>
 * @author WangJun
 * @date 2010/01/12 23:32:11
 * @version 1.0
 */
package net.donotes.blog.action;

import java.util.List;

import net.donotes.blog.dao.IngDao;
import net.donotes.blog.pojo.Ing;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @author WangJun
 *
 */
public class IngAction extends ActionSupport implements ModelDriven<Ing> {

	private static final long serialVersionUID = 1L;
	
	private List<Ing> ings = null;
	private User user = null;
	
	@Override
    public Ing getModel() {
        return ing;
    }

    private Ing ing = new Ing();
    
	public String execute() {
        UserService userService = UserServiceFactory.getUserService();
        this.user = userService.getCurrentUser();
        
		IngDao ingDao = new IngDao();
		this.ings = ingDao.listIngs(0, 50);
		return SUCCESS;
	}
	
	public String addIng() {
		IngDao ingDao = new IngDao();
		ing.setFrom("Web");
		ingDao.addIng(ing);
		return SUCCESS;
	}

	/**
	 * @return the ings
	 */
	public List<Ing> getIngs() {
		return ings;
	}

	/**
	 * @param ings the ings to set
	 */
	public void setIngs(List<Ing> ings) {
		this.ings = ings;
	}
	
	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}
}